home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earkit / mail / thor / thor25_arexx.lha / CygnusEd / CEDDownload.thor < prev    next >
Text File  |  1996-10-26  |  3KB  |  160 lines

  1. /* CEDDownload.thor · by Troels Walsted Hansen
  2. ** $VER: CEDDownload.thor v2.00 (15.09.94)
  3. **
  4. ** An ARexx script that creates a download event for the file
  5. ** under the cursor in CED.
  6. **
  7. ** Get-file-name code is a slightly modified version of
  8. ** something I found in insert_adr.ced by Dirk Federlein.  :^)
  9. **
  10. ** New: This version is for THOR v2.0 or higher.
  11. */
  12.  
  13. /* user variables. edit to your hearts content */
  14.  
  15. bbsname = "REQUEST"     /* Change REQUEST to a BBS name if you like.. */
  16.  
  17. /* needs THOR, bbsread.library, CED and rexxsupport.library functions */
  18.  
  19. options results
  20.  
  21. p = ' ' || address() || ' ' || show('P',,)
  22. thorport = pos(' THOR.',p)
  23.  
  24. if thorport > 0 then thorport = word(substr(p,thorport+1),1)
  25. else
  26. do
  27.     say 'No THOR port found!'
  28.     exit 10
  29. end
  30.  
  31. if ~show('p', 'BBSREAD') then
  32. do
  33.     address command
  34.         "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  35.         "WaitForPort BBSREAD"
  36. end
  37.  
  38. if ~show('ports','rexx_ced') then do
  39.     say "Sorry, CED's ARexx port was not found. Aborting script.."
  40.     exit
  41. end
  42.  
  43. if ~show(l, 'rexxsupport.library') then do
  44.     if ~addlib('rexxsupport.library', 0, -30) then do
  45.         say "Please install rexxsupport.library in your libs: directory"
  46.         exit
  47.     end
  48. end
  49.  
  50. address 'rexx_ced'
  51.  
  52. /* get filename */
  53.  
  54. tabchar = '09'X
  55. cr    = '0A'X
  56.  
  57. /*    Get contents of current line: */
  58. status 55
  59. line = result
  60.  
  61. /*    Get tab size: */
  62. status 8
  63. tabadjust = result - 1
  64.  
  65. /*    Get cursor x position (relative to beginning of line = 1): */
  66. status 46
  67. cur = result + 1
  68.  
  69. i = index(line,tabchar)
  70. DO while i > 0 & i <= cur - tabadjust
  71.     cur = cur - tabadjust
  72.     i = index(line,tabchar,i+1)
  73. END
  74.  
  75. /* If the current character is non-alphabetic, then start one character
  76. ** over to the left.  This allows the cursor to be immediately after
  77. ** the key word (say on a space or bracket.)
  78. */
  79.  
  80. char = substr(line,cur,1)
  81. if (~(datatype(char,'A') | char = '.' | char = '-' | char = '_' | char = '+') & cur > 1) then
  82.     cur = cur - 1
  83.  
  84. /*    Find leftmost and rightmost alphabetic character adjacent to current: */
  85.  
  86. right = cur - 1
  87. left = cur + 1
  88. char = 'A'
  89. DO while (datatype(char,'A') | char = '.' | char = '-' | char = '_' | char = '+') & (left > 0)
  90.      left = left - 1
  91.     if left > 0 then
  92.         char = substr(line,left,1)
  93. END
  94. char = 'A'
  95. DO while (datatype(char,'A') | (char = '.' | char = '-' | char = '_' | char = '+'))
  96.     right = right + 1
  97.     char = substr(line,right,1)
  98. END
  99.  
  100. if right-left <= 1 then
  101. DO
  102.     address(thorport)
  103.     THORTOFRONT
  104.     REQUESTSTRING TITLE '"Enter name of file to download:"' BT '"_Ok|_Cancel"' MAXCHARS 40
  105.     if(rc ~= 0) then
  106.     do
  107.         address 'rexx_ced'
  108.         CEDTOFRONT
  109.         exit
  110.     end
  111. end
  112. else
  113. do
  114.     EVENT.FILENAME = substr(line,left+1,right-left-1)
  115. end
  116.  
  117. /* create upload event */
  118.  
  119. address(thorport)
  120.  
  121. if(BBSname = "REQUEST") then do
  122.     address(bbsread)
  123.  
  124.     GETBBSLIST stem BBSLIST
  125.     if(rc ~= 0) then
  126.     do
  127.         address(thorport)
  128.         REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  129.         exit 5
  130.     end
  131.  
  132.     address(thorport)
  133.  
  134.     THORTOFRONT
  135.     REQUESTLIST instem BBSLIST title '"Select BBS:"' SIZEGADGET
  136.     if(rc ~= 0) then
  137.     do
  138.         address 'rexx_ced'
  139.         CEDTOFRONT
  140.         exit
  141.     end
  142.     else bbs = result
  143. end
  144.  
  145. address(bbsread)
  146.  
  147. WRITEBREVENT '"'bbs'"' event 4 stem EVENT
  148. if(rc ~= 0) then
  149. do
  150.     address(thorport)
  151.     REQUESTNOTIFY TEXT '"'BBSREAD.LASTERROR'"' BT '"_Ok"'
  152.     exit 5
  153. end
  154.  
  155. /* bye.. */
  156.  
  157. address 'rexx_ced'
  158. CEDTOFRONT
  159. exit
  160.